package com.xjn.updatetool;

import com.xjn.updatetool.service.AppExtract;
import com.xjn.updatetool.service.AppUpdater;
import com.xjn.updatetool.util.TimeUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

import java.util.Date;

@SpringBootApplication
public class UpdatetoolApplication implements CommandLineRunner {
	public static void main(String[] args) {
		SpringApplication.run(UpdatetoolApplication.class, args);
	}
	@Autowired
	private AppUpdater appUpdater;
	@Autowired
	private AppExtract appExtract;
	@Override
	public void run(String... args) throws Exception {
		System.out.println(args);
		if("after".equalsIgnoreCase(args[0])){//抽取文件
			if(args.length != 2){
				System.out.println("命令行参数错误。");
				System.out.println("java -jar updatetool-0.0.1-SNAPSHOT.jar after 20200730120000");
				return;
			}
			String afterDateString = args[1];
			Date afterDate = null;
			try {
				afterDate = TimeUtils.stringToDateyyyyMMddHHmmss(afterDateString);
				appExtract.startExtract(afterDate);
			}catch (Exception ex){
				ex.printStackTrace();
				System.out.println("命令行参数错误。");
				System.out.println("java -jar updatetool-0.0.1-SNAPSHOT.jar after 20200730120000");
				return;
			}

		}else {//部署
			appUpdater.startUpdate();
		}
	}
}
